package com.pansoft.openplanet.activity;

import android.content.Context;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.efounder.recycleviewhelper.CommonAdapter;
import com.efounder.recycleviewhelper.base.ViewHolder;
import com.efounder.tbs.Md5Tool;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.bean.Contact;

import java.util.List;

/**
 * Created by will on 18-3-21.
 */

public class MobileContactDetailActivity extends TCBaseActivity {

    private RecyclerView recyclerView;
    private TextView tvName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.talk_chain_activity_mobile_contact_detail);

        initView();
        initData();
    }

    private void initData() {
        Contact contact = (Contact) getIntent().getExtras().getSerializable("contact");
        if (contact != null) {
            tvName.setText(contact.getName());
            recyclerView.setAdapter(new MyAdapter(this, R.layout.talk_chain_item_contact_detail, contact.getPhones()));
        }
    }

    private void initView() {
        ImageView ivBack = (ImageView) findViewById(R.id.iv_back);
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        TextView tvTitle = (TextView) findViewById(R.id.tv_title);
        tvTitle.setText(R.string.common_text_contacts_detail);

        tvName = (TextView) findViewById(R.id.tv_create_hint);
        recyclerView = (RecyclerView) findViewById(R.id.contact_detail_recycler);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }


    public class MyAdapter extends CommonAdapter<Contact.Phone> {
        public MyAdapter(Context context, int layoutId, List datas) {
            super(context, layoutId, datas);
        }

        @Override
        protected void convert(ViewHolder holder, Contact.Phone phone, int position) {
            if (phone.getType() != null) {
                holder.setText(R.id.tv_type, phone.getType());
            }
            holder.setText(R.id.tv_phone, Md5Tool.hashKey(phone.getPhone()));
        }
    }
}
